package com.smec.moblie.activity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.widget.Toast;

import com.smec.moblie.R;
import com.smec.moblie.crash.ExitAppUtils;

import java.util.List;

import me.zhanghai.android.patternlock.PatternUtils;
import me.zhanghai.android.patternlock.PatternView;

/**
 * 设置手势密码
 * Created by sunyubo on 16/3/10.
 */
public class SetPatternActivity extends me.zhanghai.android.patternlock.SetPatternActivity {
    /** 是否重置手势密码 **/
    private boolean isChangePatter = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setTheme(R.style.PatterAppTheme);
        isChangePatter = getIntent().getBooleanExtra("isChangePatter",false);
        super.onCreate(savedInstanceState);
        ExitAppUtils.getInstance().addActivity(this);
    }

    @Override
    protected void onSetPattern(List<PatternView.Cell> pattern) {
        String patternSha1 = PatternUtils.patternToSha1String(pattern);
        SharedPreferences sharedPreferences = getSharedPreferences(
                "ElevatorSharedPreferences",SetPatternActivity.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences
                .edit();
        editor.putString("patternSha1", patternSha1);
        editor.putBoolean("isSetPassWord", true);
        // 提交当前数据
        editor.commit();
        if(isChangePatter) {
            Toast.makeText(this, "手势密码修改成功", Toast.LENGTH_SHORT).show();
        }else {
            Intent intent = new Intent(SetPatternActivity.this, MainActivity.class);
            startActivity(intent);
        }
    }
}
